<?php
/**
 * Created by PhpStorm.
 * User: charles
 * Date: 2017-11-18
 * Time: 04:39
 */

namespace App\Traits;

trait GetByOpenid
{
    public static function getByOpenid(string $openid)
    {
        $model = static::query()
            ->where('openid', $openid)
            ->first();
        if (null === $model) {
            $model = new static();
            $model->openid = $openid;
        }
        return $model;
    }
}